public class SolutionInterview8_3 {
    public int findMagicIndex(int[] nums) {
        for (int i=0;i<nums.length;i++){
            if (nums[i]==i){
                return i;
            }
            if (nums[i]>i){
                i=nums[i]-1;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(new SolutionInterview8_3().findMagicIndex(new int[]{0, 2, 3, 4, 5}));
    }
}
